<template>
	<view class="content">
		<!-- <u-icon class="fh" name="arrow-left" size="40" color="#000000" @click="getRouter"></u-icon> -->
		<view class="wrap">
			<u-swiper :list="list" height="750" img-mode="aspectFill"></u-swiper>
		</view>
		<view class="coupon-introduce-title">
			<view class="coupon-introduce">
				<view class="font-32 middle">{{ couponDetail.subtitle_title }}</view>
				<view class="font-32" style="color: #DD524D;">
					￥{{ couponDetail.goods_price ? couponDetail.goods_price : 0 }}</view>
			</view>
			<view style="display: flex;padding-left: 30upx;align-items: center;margin-bottom: 10upx;">
				<view style="display: flex;align-items: center;">
					<view><image src="../../static/bz.svg" style="width: 40upx;height: 40upx;margin-right: 10upx;"></image></view>
					<view style="position: relative;top: -4upx;">服务保障</view>
				</view>
				<view style="display: flex;align-items: center;margin-left: 20upx;">
					<view><image src="../../static/bz.svg" style="width: 40upx;height: 40upx;margin-right: 10upx;"></image></view>
					<view style="position: relative;top: -4upx;">24小时免费退</view>
				</view>
				<view style="display: flex;align-items: center;margin-left: 20upx;">
					<view><image src="../../static/bz.svg" style="width: 40upx;height: 40upx;margin-right: 10upx;"></image></view>
					<view style="position: relative;top: -4upx;">电话预约</view>
				</view>
			</view>	
			<u-cell-group>
					<u-cell-item icon="integral-fill" title="成为代理,分享有奖金" :border-bottom="true" @click="showdli = true"></u-cell-item>
			</u-cell-group>
		</view>
		<view :class="showmode ? 'coupon-address' : 'coupon-address-style'">
			<view class="shop-adapt">适应门店</view>
			<view class="shopping" v-for="(item, index) in couponDetail.store" :key="index">
				<view>
					<image src="../../static/shop.png" style="width: 100upx;height: 100upx;"></image>
				</view>
				<view
					style="margin-left: 20upx;display: flex;flex-direction: column;justify-content: space-between;margin-bottom: 10upx;">
					<view style="width: 300rpx;">{{ item.name }}</view>
					<view class="address">{{ item.address }}</view>
				</view>
				<view style="display: flex;color: #2B303D;align-items: center;justify-content: space-around;">
					<view style="display: flex;flex-direction: column;align-items: center;"
						@click="toNavigation(item.lng, item.lat, item.detailed_address)">
						<image src="../../static/dh.png" style="width: 58upx;height: 58upx;"></image>
						<view style="margin-top: 10upx;">导航到店</view>
					</view>
					<view class="line-y"></view>
					<view style="display: flex;flex-direction: column;align-items: center;margin-left: 20upx;"
						@click="freeTell(item.mobile)">
						<image src="../../static/lx.png" style="width: 58upx;height: 58upx;"></image>
						<view style="margin-top: 10upx;">联系商家</view>
					</view>
				</view>
			</view>
		</view>
		<view style="text-align: center;padding: 2%;background: #FFFFFF;" @click="getshowMode">查看更多 <u-icon name="arrow-down" v-if="showmode==false"></u-icon><u-icon name="arrow-up" v-if="showmode==true"></u-icon></view>
		<view class="xq-nav">
			<u-tabs style="margin-top: 10upx;" :list="listTitle" :is-scroll="false" :current="current"
				border-radius="24" @change="change()">
			</u-tabs>
			<view class="xq">
				<u-divider bg-color="#FFFFFF">{{listTitle[current].name}}</u-divider>
			</view>
			<view v-if="current === 0" style="padding: 3%;margin-bottom: 200upx;">
				<u-parse :html="couponDetail.content"></u-parse>
			</view>
			<view v-if="current === 1" style="padding: 3%;margin-bottom: 200upx;">
				<u-parse :html="couponDetail.setmeal"></u-parse>
			</view>
			<view v-if="current === 2" style="padding: 3%;margin-bottom: 200upx;">
				<u-parse :html="couponDetail.by_know"></u-parse>
				<!-- 			<view class="dd-wt">订单问题</view>
						<view class="dd-wt">押金问题</view>
						<view class="dd-wt">物料问题</view>
						<view class="dd-wt">其他问题</view> -->
			</view>
			<view class="footer">
				<!-- <u-parse :html="goodDetail.body"></u-parse> -->
			</view>
		</view>
		<view class="btn-lq">
			<view class="btn" @click="getCreate">马上购买</view>
		</view>
		<u-modal v-model="showdli" :content="content" :show-cancel-button="true" @confirm="confirm"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showdli: false,
				content: '确认提交代理申请？',
				showmode: false,
				showData: false,
				mode: 'date',
				number: 1,
				show: false,
				current: 0,
				listTitle: [{
					name: '商品详情'
				}, {
					name: '套餐详情'
				}, {
					name: '购买须知'
				}],
				user_name: '',
				phone: '',
				pw_personid_type: '',
				time: '',
				pw_playtime: '',
				pw_time_slot: '',
				couponDetail: {},
				couponAddress: {},
				list: [],
				noClick: true,
				aid: '',
			}
		},
		onLoad(e) {
			if (e.aid) {
				this.aid = e.aid
				uni.setStorageSync('aid', e.aid)
				uni.setStorageSync('good_id', e.goods_id)
			}
			if (e.id) {
				this.id = e.id
				uni.setStorageSync('good_id', e.id)
			}
		},
		onShareAppMessage(res) {
		    if (res.from === 'button') {// 来自页面内分享按钮
		      console.log(res.target)
		    }
		    return {
		      title: this.couponDetail.subtitle_title,
			  imageUrl: this.couponDetail.image[0].file_path,
		      path: '/pages/detail/index?goods_id=' + this.couponDetail.goods_id
		    }
		  },
		mounted() {
			this.getDetail()
		},
		methods: {
			confirm () {
				this.$request('', '/api/app/coupon/getuseragent', 'POST', {
					goods_id: uni.getStorageSync('good_id')
				}, {}).then(res => {
					uni.showToast({
						title: '申请提交成功',
						icon: 'success',
						duration: 2000
					});
				})
			},
			getshowMode () {
				this.showmode = !this.showmode
			},
			changeDate(e) {
				this.time = e.startDate + '~' + e.endDate
				this.pw_playtime = e.startDate
				this.pw_time_slot = e.endDate
				console.log(e);
			},
			getCreate() {
				uni.navigateTo({
					url:'/pages/order/index'
				})
			},
			// 创建订单
			creater_order() {
				this.$request('', '/api/app/huibendi/getopenapicreateorder', 'POST', {
					goods_id: uni.getStorageSync('good_id'),
					user_name: this.user_name,
					phone: this.phone,
					goods_num: this.number,
					pw_playtime: this.pw_playtime,
					pw_time_slot: this.pw_time_slot,
					pw_personid_type: this.pw_personid_type
				}, {}).then(res => {
					this.getpay(res.data)
				})
			},
			// 获取支付参数
			getpay(val) {
				var that = this
				this.$request('', '/api/app/coupon/payment', 'POST', {
					openid: uni.getStorageSync('openid'),
					goods_id: uni.getStorageSync('good_id'),
					num: val.order_total_num,
					fee: val.order_total_price,
					order_no: val.order_no
				}, {}).then(responss => {
					console.log(responss.data)
					uni.requestPayment({
						provider: 'wxpay',
						timeStamp: responss.data.timestamp,
						nonceStr: responss.data.nonceStr,
						package: responss.data.package,
						signType: responss.data.signType,
						paySign: responss.data.paySign,
						success: function(res) {
							that.$request('', '/api/app/huibendi/getopenapiorderpay', 'POST', {
								order_no: val.order_no
							}, {}).then(respons => {
								that.$request('', '/api/app/coupon/xcxqueryorder', 'POST', {
									out_trade_no: responss.out_trade_no
								}, {}).then(respons => {
									uni.navigateTo({
										url: '/pages/coupon/index'
									})
								})
								that.$request('', '/api/app/huibendi/getopenapivercodedetail',
									'POST', {
										order_no: val.order_no
									}, {}).then(respons => {

								})
							})
						},
						fail: function(err) {
							console.log('fail:' + JSON.stringify(err));
						}
					});
					// this.$request('', '/api/app/huibendi/getopenapiorderpay', 'POST', {
					// 	order_no: val
					// }, {}).then(respons => {

					// })
				})
			},
			// 订单支付

			valChange() {},
			getDetail() {
				this.$request('', '/api/app/coupon/coupondev', 'POST', {
					goods_id: uni.getStorageSync('good_id')
				}, {}).then(res => {
					this.couponDetail = res.data
					for (let i in res.data.image) {
						this.list.push({
							title: i,
							image: res.data.image[i].file_path
						})
					}
				})
			},
			getRouter() {
				if (uni.getStorageSync('shopid')) {
					uni.navigateTo({
						url: '/pages/merchant/index?shopid=' + uni.getStorageSync('shopid')
					})
				} else {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}

			},
			freeTell(tel) {

				uni.makePhoneCall({

					phoneNumber: tel,

				})

			},
			change(index) {
				this.current = index;
			},
			toNavigation(lng, lat, detailed_address) {
				// console.log(val)
				var o = {
					name: detailed_address,
					location: {
						lat: lat,
						lng: lng
					}
				};
				uni.navigateToMiniProgram({
					appId: 'wx7643d5f831302ab0',
					path: "pages/multiScheme/multiScheme?endLoc=" + JSON.stringify(o) + "&qbMode=0",
					success(res) {
						// 打开成功
					}
				})
			},
			getCoupon(id) {


				if (this.noClick) {
					uni.showLoading({
						title: '加载中'
					});
					this.noClick = false;
					uni.showLoading({
						title: '加载中'
					});
					this.$request('', '/api/coupon/coupondev', 'POST', {
						wechat_api_shopcoupon_id: this.couponDetail.id,
						templatemsgid: '3ESm4eqBhFFuqUr79nsJ9HzjjwlQkgO6ORaTFLmI2_Y,LbihvAdZ-8RrtsZz9Bnns5i6QxHwhO-L93vqv4p5So0,LbihvAdZ-8RrtsZz9Bnns2dhoRGfBJDxrdISJ9D55ss',
						ordersn: uni.getStorageSync('ordersn'),
						openid: uni.getStorageSync('openid'),
						token: uni.getStorageSync('token')
					}, {}).then(res => {

						if (res.status == 1) {
							uni.navigateTo({
								url: '/pages/coupon/index'
							})
							uni.showToast({
								title: '领取成功',
								icon: 'success',
								duration: 2000
							});
							this.data = res.data.data
						} else {
							uni.showToast({
								title: '领取失败',
								icon: 'error',
								duration: 2000
							});
						}
						setTimeout(() => {
							console.log(111);
							this.noClick = true;
						}, 4000)
					})
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.shop-adapt {
		font-weight: bold;
		font-size: 35upx;
		padding-left: 10upx;
		margin-left: 10upx;
		// padding-top: 10upx;
		margin-top: 10upx;
		border-left: 10upx solid #E43D33;
	}
	.title-popup {
		width: 100%;
		text-align: center;
		font-size: 35upx;
		font-weight: bold;
		padding-top: 20upx;
	}

	.number {
		width: 100%;
		display: flex;
		justify-content: space-between;
		padding-left: 55upx;
		padding-right: 20upx;
		margin-top: 30upx;
	}

	.middle {
		vertical-align: middle;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.line-y {
		width: 2upx;
		height: 80upx;
		background: #D8D8D8;
		margin-left: 5upx;
		margin-right: 5upx;
	}

	.fh {
		position: absolute;
		top: 120upx;
		z-index: 99;
		margin-left: 20upx;
	}

	.btn-lq {
		width: 750upx;
		height: 178upx;
		background: #FFFFFF;
		box-shadow: 0upx -8upx 16upx 0upx rgba(0, 0, 0, 0.1);
		border-radius: 40upx 40upx 0upx 0upx;
		position: fixed;
		bottom: 0;
		display: flex;
		justify-content: center;
		align-items: center;

		.btn {
			width: 90%;
			height: 76upx;
			background: #FFD103;
			border-radius: 38upx;
			line-height: 76upx;
			text-align: center;
		}
	}

	.font-24 {
		font-size: 24upx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #A7ABB6;
	}

	.font-32 {
		font-size: 32upx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #2B303D;
	}

	.font-styless {
		padding: 32upx;

		view {
			margin-top: 10upx;
		}
	}

	.content {
		width: 100%;
		height: 100vh;
		background-color: #EDEDED;
	}

	.coupon-introduce {
		background-color: #FFFFFF;
		width: 100%;
		height: 120upx;
		border-radius: 0upx 0upx 16upx 16upx;
		padding-left: 32upx;
		padding-right: 32upx;
		padding-top: 32upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}
	.coupon-introduce-title{
		background-color: #FFFFFF;
		width: 100%;
		// display: flex;
		
	}

	.coupon-address {
		width: 750upx;
		// height: 260upx;
		background: #FFFFFF;
		border-radius: 16upx;
		margin-top: 24upx;

		.title {
			padding-top: 32upx;
			padding-left: 32upx;
			font-size: 32upx;
			font-family: PingFangSC-Semibold, PingFang SC;
			font-weight: 600;
			color: #2B303D;
		}

		.shopping {
			display: flex;
			padding-left: 32upx;
			padding-top: 32upx;
			.address {
				width: 292upx;
				// height: 66upx;
				font-size: 24upx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #A7ABB6;
				line-height: 33upx;
				margin-top: 16upx;
			}
		}
	}
	
	.coupon-address-style {
		width: 750upx;
		height: 230upx;
		background: #FFFFFF;
		border-radius: 16upx;
		margin-top: 24upx;
		overflow: hidden;
		.title {
			padding-top: 32upx;
			padding-left: 32upx;
			font-size: 32upx;
			font-family: PingFangSC-Semibold, PingFang SC;
			font-weight: 600;
			color: #2B303D;
		}
	
		.shopping {
			display: flex;
			padding-left: 32upx;
			padding-top: 32upx;
			// height: 300upx;
			.address {
				width: 292upx;
				// height: 66upx;
				font-size: 24upx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #A7ABB6;
				line-height: 33upx;
				margin-top: 16upx;
			}
		}
		.shopping-style{
			display: flex;
			padding-left: 32upx;
			padding-top: 32upx;
			
			.address {
				width: 292upx;
				// height: 66upx;
				font-size: 24upx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #A7ABB6;
				line-height: 33upx;
				margin-top: 16upx;
			}
		}
	}
	
	
	
	
	
	

	.coupon-attention {
		width: 750upx;
		height: 453upx;
		background: #FFFFFF;
		border-radius: 16upx;
		margin-top: 24upx;
		margin-bottom: 280upx;
		padding-bottom: 50upx;

		.title {
			padding-top: 32upx;
			padding-left: 32upx;
			font-size: 32upx;
			font-family: PingFangSC-Semibold, PingFang SC;
			font-weight: 600;
			color: #2B303D;
		}

		.coupon-gz {
			display: flex;
			justify-content: space-around;
			margin-top: 32upx;
		}
	}

	.xq-nav {
		width: 100%;
		margin: 0 auto;
		background-color: #FFFFFF;
		margin-top: 30upx;
	}

	.xq {
		// background-color: red;
		margin-top: 40upx;
	}
</style>
